package com.xszn.middleware.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xszn.middleware.entity.RYQueryCondition;
import com.xszn.middleware.entity.RYRequestEntity;
import com.xszn.middleware.entity.RYResponseEntity;

import com.xszn.middleware.service.HardwareInterface;
import com.xszn.middleware.util.WebSocketUsers;
import org.springframework.stereotype.Service;
import javax.websocket.Session;
import java.util.HashMap;
import java.util.Map;

@Service
public class RuoyingServiceImpl implements HardwareInterface<RYResponseEntity, RYQueryCondition> {

    @Override
    public RYResponseEntity queryPeople(Session session,RYQueryCondition condition)  {
      try{
          RYRequestEntity ryRequestEntity = new RYRequestEntity();
          ryRequestEntity.setMethod("personManager.getPersons");
          Map<String, RYQueryCondition> map = new HashMap<>();
          map.put("Condition", condition);
          ryRequestEntity.setParams(map);
          ObjectMapper objectMapper = new ObjectMapper();
          String json = objectMapper.writeValueAsString(ryRequestEntity);

          WebSocketUsers.sendMessageToUserByText(session, json);
      }catch(JsonProcessingException exception){

      }
        return null;
    }

    @Override
    public RYResponseEntity storageFace(Session session) {
        return null;
    }

    @Override
    public RYResponseEntity deleteFace(Session session) {
        return null;
    }

    @Override
    public RYResponseEntity openDoor(Session session) {
        return null;
    }
}

